<?php

$data = $_POST;


$oldArr = file_get_contents("./data/user.txt");

$oldArr = json_decode($oldArr,true);

var_dump($oldArr);


foreach ($oldArr as $user) {
	if($user['nickname']==$data['nickname'] && $user['password']==md5($data['password'])){
		
		session_start();

		$_SESSION['nickname'] = $data['nickname'];
		$_SESSION['email'] = $user['email'];

		if(isset($data['remenber'])){
			setcookie(session_name(),session_id(),time()+7*86400);
		}

		echo '<script type="text/javascript">if(confirm("登录成功")){location.href ="./index.php"}</script>';

		exit;
	}
}

echo '<script type="text/javascript">if(confirm("用户名或者密码不正确")){location.href ="./login.php"}</script>';
exit;